package ooday04;

public class MultipleTypeDemo {
    public static void main(String[] args) {
      /*  Animal o =new Dog("小黑",2,"黑");
        Dog g = (Dog)o;
        Swim s=(Swim)o;
        //Fish f = (Fish)o;
        System.out.println(o instanceof Dog);  //true
        System.out.println(o instanceof Swim); //true
        System.out.println(o instanceof Fish); //false

        if(o instanceof Fish){ //false
            Fish f = (Fish)o;
        }*/















        Animal[] animals =new Animal[5];
        animals[0] =new Dog("小黑",2,"黑");
        animals[1]=new Dog("小花",3,"金");
        animals[2] =new Chick("小金",1,"金");
        animals[3] =new Chick("小花",1,"花");
        animals[4] =new Fish("小灰",1,"灰");
       for (int i=0;i<animals.length;i++){
           System.out.println(animals[i].name);
           animals[i].drink();
           animals[i].eat();

           if(animals[i] instanceof  Dog){
               Dog dog=(Dog) animals[i];
               dog.lookHome();
           }
           if(animals[i]instanceof Chick){
               Chick chick=(Chick) animals[i];
               chick.layEggs();
           }
           if(animals[i] instanceof Swim){
               Swim s =(Swim)animals[i];
               s.swim();
           }
       }
    }
}
